// app/controller/sendEmail.js

"use strict";

const Controller = require("egg").Controller;
class sendController extends Controller {
  // 发送邮件
  async send() {
    const { ctx } = this;
    const {email} = ctx.request.body 
    if(!email) return ctx.responseData(null, "未传入邮箱号", 1)
    const result = await ctx.service.sendEmail.sendEmail(email);
    ctx.body = {
        ...result
    };
  }

  // 验证核实
  async verify() { 
    const { ctx } = this;
    // 获取 Redis 键值对
    const redisCode = await ctx.app.redis.get(ctx.query.account);
    const verifyCode = ctx.query.verifyCode
    redisCode == verifyCode ? ctx.responseData({}, "success", 0) : ctx.responseData({}, "fail", 1)
  }
}

module.exports = sendController;
